import {getGiveRecords} from "@src/api/member";
import router from "@src/router";

Component({
  behaviors: [router.routerBehavior],
  options: {
    addGlobalClass: true
  },
  data: {
    pageSize: 10,
    pageNum: 1,
    hasNextPage: false,
    loading: false,
    listData: []
  },
  lifetimes: {
    ready() {
      this.fetchData();
    }
  },
  methods: {
    onReachBottom() {
      if (this.data.hasNextPage) {
        this.setData({pageNum: this.data.pageNum + 1});
        this.fetchData();
      }
    },
    onPullDownRefresh() {
      wx.stopPullDownRefresh();
      this.setData({pageNum: 1, pageSize: 10, hasNextPage: false, listData: []});
      this.fetchData();
    },
    fetchData() {
      let data = {
        page: this.data.pageNum,
        pageSize: this.data.pageSize
      }
      getGiveRecords(data).then(res => {
        let list = res.data.list;
        let listData = this.data.listData.concat(list);
        this.setData({listData, hasNextPage: res.data.hasNextPage})
      })
    }
  }
});
